Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add header input type to support multi headers #8

Merged
merged 16 commits into from
Feb 27, 2024

Conversation

NinaFan0824
Copy link

@NinaFan0824 NinaFan0824 commented Feb 20, 2024

  1. Some headers have default values, for example, the assignment rule header is default to true, which we want to update https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_autoassign.htm
  2. We also need some headers to make Salesforce Conditional updates Feat/support modification since #5, at the meantime, handle the errors that is likely to be returned when the object doesn't match the conditions. https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest_conditional_requests.htm

Currently, ts-force doesn't support adding headers. Based on this, we add some headers to send in patch requests. The below are the headers we intend to add.

Sforce-Auto-Assign: FALSE
If-Match: "Jbjuzw7dbhaEG3fd90kJbx6A0ow=-gzip", "U5iWijwWbQD18jeiXwsqxeGpZQk=-gzip"
If-None-Match: "Jbjuzw7dbhaEG3fd90kJbx6A0ow=-gzip", "U5iWijwWbQD18jeiXwsqxeGpZQk=-gzip"
If-Modified-Since: Tue, 10 Aug 2015 00:00:00 GMT
If-Unmodified-Since: Tue, 10 Aug 2015 00:00:00 GMT
Sforce-Mru: updateMru=true
x-sfdc-packageversion-clientPackage: 1.0 //x-sfdc-packageversion-[namespace]: xx.x , where [namespace] is the unique namespace of the managed package and xx.x is the package version.

@NinaFan0824 NinaFan0824 marked this pull request as ready for review February 21, 2024 04:05
'If-Unmodified-Since'?: Date;
'If-Match'?: string[];
'If-None-Match'?: string[];
'Generic-Header'?: GenericHeader;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Generic-Header just allowing an arbitrary header key/value?

If so, it seems like you would want to potentially support multiple values. It might also be easier to just allow a Record<string, string>.

additionalHeaders?: Record<string, string>;

ConditionalRequestHeaders.includes(key as keyof RequestHeadersInput)
);
if (containsConditionalHeader && (response.status === 304 || response.status === 412)) {
throw new ConditionalError('Conditions not met');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to include the header keys in the exception


export const ConditionalRequestHeaders: (keyof RequestHeadersInput)[] = [
'If-Match',
'If-None-Match',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never actually used these etag caching headers with Salesforce... Reviewing the docs, I see this statement:

An optional header specifying a comma-delimited list of one or more ETags. This only has an effect when used with Account objects. The request is only processed if the Account’s ETag does not match one of the ETags in the list.

Does it really only work with Account?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the document here, Etag is used for http caching. I guess that’s the reason why it’s said only work with Account. I test with a a case project, and If-Match and If-None-Match can be added on get request but not on patch request.
Screenshot 2024-02-23 at 9 20 14 AM
Screenshot 2024-02-23 at 9 19 46 AM

@@ -6,8 +6,6 @@ import { getCalendarDate } from '../../utils/calendarDate';
import { Account, Contact, User } from '../assets/sobs';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend undoing the formatting changes

@@ -1,6 +1,6 @@
{
"name": "@vacasaoss/ts-force-gen",
"version": "3.4.4",
"version": "3.4.5",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change? Should we increment the major version?

@NinaFan0824 NinaFan0824 merged commit bf328b9 into master Feb 27, 2024
2 checks passed
@NinaFan0824 NinaFan0824 deleted the feat/support-multi-header branch February 27, 2024 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants